Return to start page

Systems/Character/Struct Character.j

Code

		
1			library AStructSystemsCharacterCharacter requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, AStructCoreGeneralVector, ALibraryCoreGeneralPlayer, ALibraryCoreGeneralUnit, ALibraryCoreInterfaceCinematicFilter, ALibraryCoreInterfaceCamera, ALibraryCoreMathsUnit, AStructSystemsCharacterAbstractCharacterSystem
2
3 /**
4 * This struct represents a single RPG character. Each player can own exactly one character.
5 * You can configure the character systems and enable or disable the several character system modules.
6 * Each module makes the system requiring more memory, so clearly think of which system modules are required and which aren't.
7 */
8 struct ACharacter
9 //static constant members
10 public static constant integer messageTypeInfo = 0
11 public static constant integer messageTypeError = 1
12 //static start members
13 private static boolean m_removeUnitOnDestruction
14 private static boolean m_destroyOnPlayerLeaves
15 private static boolean m_shareOnPlayerLeaves
16 private static boolean m_destroyOnDeath
17 private static boolean m_useViewSystem
18 private static boolean m_useFocusSystem
19 private static boolean m_useMovementSystem
20 private static boolean m_useFightSystem
21 private static boolean m_useRevivalSystem
22 private static boolean m_useInventorySystem
23 private static boolean m_useTalkLogSystem
24 //static members
25 private static thistype array m_playerCharacter[12] //[bj_MAX_PLAYERS] vjass bug
26 //dynamic members
27 private boolean m_isMovable
28 private AClass m_class //No system
29 private ATalk m_talk //No system
30 private AShrine m_shrine //No system
31 //start members
32 private player m_user
33 private unit m_unit
34 //members
35 private trigger m_leaveTrigger
36 private trigger m_deathTrigger
37 //insert the character systems here
38 private AView m_view
39 private AFocus m_focus
40 private AMovement m_movement
41 private AFight m_fight
42 private ARevival m_revival
43 private AInventory m_inventory
44 private ATalkLog m_talkLog
45 private AIntegerVector m_spells
46
47 //! runtextmacro optional A_STRUCT_DEBUG("\"ACharacter\"")
48
49 //dynamic members
50
51 /**
52 * If the character is set unmovable he will be stopped immediatly and can not move until he will be set movable.
53 * This method is used for dialogs or cinematic sequences.
54 * Besides it disables all character systems!
55 */
56 public method setMovable takes boolean movable returns nothing
57 //Don't make him movable if he is already!
58 //If he talks with another NPC he is already unmovable.
59 debug if (this.m_isMovable == movable) then
60 debug call this.print("setMovable() error.")
61 debug return
62 debug endif
63 set this.m_isMovable = movable
64 call IssueImmediateOrder(this.m_unit, "stop") //new, required?!
65 call PauseUnit(this.m_unit, not movable)
66 call SetUnitInvulnerable(this.m_unit, not movable)
67 if (movable) then
68 call this.enableMovableSystems()
69 else
70 call this.disableMovableSystems()
71 endif
72 endmethod
73
74 /**
75 * @return Returns if the character is movable. Unmovable characters are paused and invulnerable. Additionally all systems are disabled.
76 * @see setMovable
77 */
78 public method isMovable takes nothing returns boolean
79 return this.m_isMovable
80 endmethod
81
82 /// Friend relation to AClassSelection, don't use.
83 public method setClass takes AClass class returns nothing
84 set this.m_class = class
85 endmethod
86
87 /**
88 * @return Returns class of the character. Classes are used by class selection which allows user to choose between different classes/unit types which are during the game.
89 * @see AClass
90 * @see AClassSelection
91 */
92 public method class takes nothing returns AClass
93 return this.m_class
94 endmethod
95
96 /// Friend relation to ATalk, don't use.
97 public method setTalk takes ATalk talk returns nothing
98 set this.m_talk = talk
99 endmethod
100
101 /// Friend relation to ATalk, don't use.
102 public method talk takes nothing returns ATalk
103 return this.m_talk
104 endmethod
105
106 /// Friend relation to AShrine, don't use.
107 public method setShrine takes AShrine shrine returns nothing
108 set this.m_shrine = shrine
109 endmethod
110
111 /// Friend relation to AShrine, don't use.
112 public method shrine takes nothing returns AShrine
113 return this.m_shrine
114 endmethod
115
116 //start members
117
118 /**
119 * Each character has its own owner. This must be a human playing player.
120 * Each human playing player can own exact one character.
121 * @return Returns character's owning player
122 */
123 public method user takes nothing returns player
124 return this.m_user
125 endmethod
126
127 /**
128 * Characters are represented by units in game.
129 * @return Returns character's unit.
130 */
131 public method unit takes nothing returns unit
132 return this.m_unit
133 endmethod
134
135 //members
136
137 public method view takes nothing returns AView
138 return this.m_view
139 endmethod
140
141 public method focus takes nothing returns AFocus
142 return this.m_focus
143 endmethod
144
145 public method movement takes nothing returns AMovement
146 return this.m_movement
147 endmethod
148
149 public method fight takes nothing returns AFight
150 return this.m_fight
151 endmethod
152
153 /// Friend relation to AShrine.
154 /// Use it to setup the time.
155 public method revival takes nothing returns ARevival
156 return this.m_revival
157 endmethod
158
159 public method inventory takes nothing returns AInventory
160 return this.m_inventory
161 endmethod
162
163 public method talkLog takes nothing returns ATalkLog
164 return this.m_talkLog
165 endmethod
166
167 public method spellCount takes nothing returns integer
168 return this.m_spells.size()
169 endmethod
170
171 //convenience methods
172
173 public method name takes nothing returns string
174 return GetPlayerName(this.m_user)
175 endmethod
176
177 /**
178 * Displays a message to the owner of the character.
179 * @todo Change this method.
180 * @param messageType The message type.
181 * @param message The message text.
182 */
183 public method displayMessage takes integer messageType, string message returns nothing
184 call DisplayTimedTextToPlayer(this.m_user, 0.0, 0.0, 6.0, message)
185 endmethod
186
187 /// Displays a message to the owners of all other characters.
188 public method displayMessageToAllOthers takes integer messageType, string message returns nothing
189 local integer i
190 local player user
191 set i = 0
192 loop
193 exitwhen (i == bj_MAX_PLAYERS)
194 set user = Player(i)
195 if (user != this.m_user) then
196 call thistype.playerCharacter(user).displayMessage(messageType, message)
197 endif
198 set user = null
199 set i = i + 1
200 endloop
201 endmethod
202
203 public method addLevels takes integer levels, boolean showEffect returns nothing
204 call SetHeroLevel(this.m_unit, GetHeroLevel(this.m_unit) + levels, showEffect)
205 endmethod
206
207 public method addSkillPoints takes integer skillPoints returns boolean
208 return UnitModifySkillPoints(this.m_unit, skillPoints)
209 endmethod
210
211 public method removeSkillPoints takes integer skillPoints returns boolean
212 return UnitModifySkillPoints(this.m_unit, -skillPoints)
213 endmethod
214
215 public method addExperience takes integer experience, boolean showEffect returns nothing
216 call AddHeroXP(this.m_unit, experience, showEffect)
217 endmethod
218
219 public method addStrength takes integer strength returns nothing
220 call SetHeroStr(this.m_unit, GetHeroStr(this.m_unit, false) + strength, true)
221 endmethod
222
223 public method addAgility takes integer agility returns nothing
224 call SetHeroAgi(this.m_unit, GetHeroAgi(this.m_unit, false) + agility, true)
225 endmethod
226
227 public method addIntelligence takes integer intelligence returns nothing
228 call SetHeroInt(this.m_unit, GetHeroInt(this.m_unit, false) + intelligence, true)
229 endmethod
230
231 public method addGold takes integer gold returns nothing
232 call SetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_GOLD) + gold)
233 endmethod
234
235 public method removeGold takes integer gold returns nothing
236 call SetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_GOLD) - gold)
237 endmethod
238
239 public method gold takes nothing returns integer
240 return GetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_GOLD)
241 endmethod
242
243 public method addLumber takes integer lumber returns nothing
244 call SetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_LUMBER) + lumber)
245 endmethod
246
247 public method removeLumber takes integer lumber returns nothing
248 call SetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_LUMBER) - lumber)
249 endmethod
250
251 public method lumber takes nothing returns integer
252 return GetPlayerState(this.m_user, PLAYER_STATE_RESOURCE_LUMBER)
253 endmethod
254
255 public method showCinematicFilter takes real duration, blendmode blendMode, string texture, real red0, real green0, real blue0, real transparency0, real red1, real green1, real blue1, real transparency1 returns nothing
256 call ShowGenericCinematicFilterForPlayer(this.m_user, duration, blendMode, texture, red0, green0, blue0, transparency0, red1, green1, blue1, transparency1)
257 endmethod
258
259 public method showBlackScreenCinematicFilter takes real duration returns nothing
260 call ShowBlackScreenCinematicFilterForPlayer(this.m_user, duration)
261 endmethod
262
263 public method setX takes real x returns nothing
264 call SetUnitX(this.m_unit, x)
265 endmethod
266
267 public method setY takes real y returns nothing
268 call SetUnitY(this.m_unit, y)
269 endmethod
270
271 public method setPosition takes real x, real y returns nothing
272 call SetUnitX(this.m_unit, x)
273 call SetUnitY(this.m_unit, y)
274 endmethod
275
276 public method setLocation takes location usedLocation returns nothing
277 call this.setX(GetLocationX(usedLocation))
278 call this.setY(GetLocationY(usedLocation))
279 endmethod
280
281 public method setRect takes rect usedRect returns nothing
282 call this.setX(GetRectCenterX(usedRect))
283 call this.setY(GetRectCenterY(usedRect))
284 endmethod
285
286 public method setFacing takes real facing returns nothing
287 call SetUnitFacing(this.m_unit, facing)
288 endmethod
289
290 public method show takes boolean show returns nothing
291 call ShowUnit(this.m_unit, show)
292 endmethod
293
294 public method select takes boolean single returns nothing
295 if (single) then
296 call ClearSelectionForPlayer(this.m_user)
297 endif
298 call SelectUnitAddForPlayer(this.m_unit, this.m_user)
299 endmethod
300
301 public method panCamera takes nothing returns nothing
302 call PanCameraToForPlayer(this.m_user, GetUnitX(this.m_unit), GetUnitY(this.m_unit))
303 endmethod
304
305 public method panCameraSmart takes nothing returns nothing
306 call SmartCameraPanWithZForPlayer(this.m_user, GetUnitX(this.m_unit), GetUnitY(this.m_unit), 0.0, 0.0)
307 endmethod
308
309 public method setCamera takes nothing returns nothing
310 call SetCameraPositionForPlayer(this.m_user, GetUnitX(this.m_unit), GetUnitY(this.m_unit))
311 endmethod
312
313 public method setCameraBoundsToRect takes rect usedRect returns nothing
314 call SetCameraBoundsToRectForPlayerBJ(this.m_user, usedRect)
315 endmethod
316
317 public method resetCameraBoundsToMapRect takes nothing returns nothing
318 call ResetCameraBoundsToMapRectForPlayer(this.m_user)
319 endmethod
320
321 public method userId takes nothing returns integer
322 return GetPlayerId(this.m_user)
323 endmethod
324
325 public method level takes nothing returns integer
326 return GetHeroLevel(this.m_unit)
327 endmethod
328
329 public method skillPoints takes nothing returns integer
330 return GetHeroSkillPoints(this.m_unit)
331 endmethod
332
333 public method copy takes integer stateMethod returns unit
334 return CopyUnit(this.m_unit, GetUnitX(this.m_unit), GetUnitY(this.m_unit), GetUnitFacing(this.m_unit), stateMethod)
335 endmethod
336
337 public method shareControl takes boolean share returns nothing
338 local player whichPlayer
339 local integer i = 0
340 loop
341 exitwhen (i == bj_MAX_PLAYERS)
342 if (i != GetPlayerId(this.m_user)) then
343 set whichPlayer = Player(i)
344 call SetPlayerAlliance(this.m_user, whichPlayer, ALLIANCE_SHARED_CONTROL, share)
345 set whichPlayer = null
346 endif
347 set i = i + 1
348 endloop
349 endmethod
350
351 //methods
352
353 /**
354 * Refresh events (without death events, there won't be any revival).
355 * Only use this method when replacing the character's unit for some time.
356 */
357 public method replaceUnit takes unit newUnit returns nothing
358 set this.m_unit = newUnit
359 endmethod
360
361 /// Friend relation to @struct ASpell, don't use.
362 public method addSpell takes ASpell spell returns nothing
363 call this.m_spells.pushBack(spell)
364 endmethod
365
366 /// Friend relation to @struct ASpell, don't use.
367 public method removeSpell takes ASpell spell returns nothing
368 call this.m_spells.remove(spell)
369 endmethod
370
371 public method spell takes integer index returns ASpell
372 return this.m_spells[index]
373 endmethod
374
375 public method spellByAbilityId takes integer abilityId returns ASpell
376 local integer i = 0
377 loop
378 exitwhen (i == this.m_spells.size())
379 if (ASpell(this.m_spells[i]).ability() == abilityId) then
380 return ASpell(this.m_spells[i])
381 endif
382 set i = i + 1
383 endloop
384 return 0
385 endmethod
386
387 private method enableMovableSystems takes nothing returns nothing
388 if (thistype.m_useViewSystem and this.m_view.enableAgain()) then
389 call this.m_view.enable()
390 endif
391 if (thistype.m_useFocusSystem and this.m_focus.enableAgain()) then
392 call this.m_focus.enable()
393 endif
394 if (thistype.m_useMovementSystem and this.m_movement.enableAgain()) then
395 call this.m_movement.enable()
396 endif
397 if (thistype.m_useFightSystem and this.m_fight.enableAgain()) then
398 call this.m_fight.enable()
399 endif
400 if (thistype.m_useRevivalSystem and this.m_revival.enableAgain()) then
401 call this.m_revival.enable()
402 endif
403 /*
404 if (thistype.m_useInventorySystem and this.m_inventory.enableAgain()) then
405 call this.m_inventory.enable()
406 endif
407 if (thistype.m_useTalkLogSystem and this.m_talkLog.enableAgain()) then
408 call this.m_talkLog.enable()
409 endif
410 */
411 endmethod
412
413 private method disableMovableSystems takes nothing returns nothing
414 if (thistype.m_useViewSystem and this.m_view.isEnabled()) then
415 call this.m_view.disable()
416 endif
417 if (thistype.m_useFocusSystem and this.m_focus.isEnabled()) then
418 call this.m_focus.disable()
419 endif
420 if (thistype.m_useMovementSystem and this.m_movement.isEnabled()) then
421 call this.m_movement.disable()
422 endif
423 if (thistype.m_useFightSystem and this.m_fight.isEnabled()) then
424 call this.m_fight.disable()
425 endif
426 if (thistype.m_useRevivalSystem and this.m_revival.isEnabled()) then
427 call this.m_revival.disable()
428 endif
429 /*
430 if (thistype.m_useInventorySystem and this.m_inventory.isEnabled()) then
431 call this.m_inventory.disable()
432 endif
433 if (thistype.m_useTalkLogSystem and this.m_talkLog.isEnabled()) then
434 call this.m_talkLog.disable()
435 endif
436 */
437 endmethod
438
439 private static method triggerActionDestroyCharacter takes nothing returns nothing
440 local trigger triggeringTrigger = GetTriggeringTrigger()
441 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
442 call thistype.destroy(this)
443 set triggeringTrigger = null
444 endmethod
445
446 private static method triggerActionShareControl takes nothing returns nothing
447 local trigger triggeringTrigger = GetTriggeringTrigger()
448 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
449 call this.shareControl(true)
450 set triggeringTrigger = null
451 endmethod
452
453 private method createLeaveTrigger takes nothing returns nothing
454 local event triggerEvent
455 local triggeraction triggerAction
456 set this.m_leaveTrigger = CreateTrigger()
457 set triggerEvent = TriggerRegisterPlayerEvent(this.m_leaveTrigger, this.m_user, EVENT_PLAYER_LEAVE)
458 if (thistype.m_destroyOnPlayerLeaves) then
459 set triggerAction = TriggerAddAction(this.m_leaveTrigger, function thistype.triggerActionDestroyCharacter)
460 elseif (thistype.m_shareOnPlayerLeaves) then
461 set triggerAction = TriggerAddAction(this.m_leaveTrigger, function thistype.triggerActionShareControl)
462 endif
463 call AHashTable.global().setHandleInteger(this.m_leaveTrigger, "this", this)
464 set triggerEvent = null
465 set triggerAction = null
466 endmethod
467
468 /// DON'T MAKE HIM UNMOVABLE, disables all systems!
469 private method createDeathTrigger takes nothing returns nothing
470 local event triggerEvent
471 local triggeraction triggerAction
472 set this.m_deathTrigger = CreateTrigger()
473 set triggerEvent = TriggerRegisterUnitEvent(this.m_deathTrigger, this.m_unit, EVENT_UNIT_DEATH)
474 set triggerAction = TriggerAddAction(this.m_deathTrigger, function thistype.triggerActionDestroyCharacter)
475 call AHashTable.global().setHandleInteger(this.m_deathTrigger, "this", this)
476 set triggerEvent = null
477 set triggerAction = null
478 endmethod
479
480 private method createSystems takes nothing returns nothing
481 if (thistype.m_useViewSystem) then
482 set this.m_view = AView.create(this)
483 endif
484 if (thistype.m_useFocusSystem) then
485 set this.m_focus = AFocus.create(this)
486 endif
487 if (thistype.m_useMovementSystem) then
488 set this.m_movement = AMovement.create(this)
489 endif
490 if (thistype.m_useFightSystem) then
491 set this.m_fight = AFight.create(this)
492 endif
493 if (thistype.m_useRevivalSystem) then
494 set this.m_revival = ARevival.create(this)
495 endif
496 if (thistype.m_useInventorySystem) then
497 set this.m_inventory = AInventory.create(this)
498 endif
499 if (thistype.m_useTalkLogSystem) then
500 set this.m_talkLog = ATalkLog.create(this)
501 endif
502 endmethod
503
504 /// @todo Should be private, vJass bug
505 //Private, every player only can have one character
506 private static method create takes player user, unit usedUnit returns thistype
507 local thistype this = thistype.allocate()
508 //start members
509 set this.m_user = user
510 set this.m_unit = usedUnit
511 call AHashTable.global().setHandleInteger(usedUnit, "ACharacter", this)
512 //dynamic members
513 set this.m_isMovable = true
514 //members
515 set this.m_inventory = 0
516 set this.m_talkLog = 0
517 set this.m_spells = AIntegerVector.create()
518
519 if (thistype.m_destroyOnPlayerLeaves or thistype.m_shareOnPlayerLeaves) then
520 call this.createLeaveTrigger()
521 endif
522 if (thistype.m_destroyOnDeath) then
523 call this.createDeathTrigger()
524 endif
525 call this.createSystems()
526 return this
527 endmethod
528
529 private method removeUnit takes nothing returns nothing
530 if (thistype.m_removeUnitOnDestruction) then
531 call RemoveUnit(this.m_unit)
532 endif
533 call AHashTable.global().flushHandle(this.m_unit)
534 set this.m_unit = null
535 endmethod
536
537 private method destroyLeaveTrigger takes nothing returns nothing
538 call AHashTable.global().destroyTrigger(this.m_leaveTrigger)
539 set this.m_leaveTrigger = null
540 endmethod
541
542 private method destroyDeathTrigger takes nothing returns nothing
543 call AHashTable.global().destroyTrigger(this.m_deathTrigger)
544 set this.m_deathTrigger = null
545 endmethod
546
547 private method destroySystems takes nothing returns nothing
548 //ifs are important
549 if (thistype.m_useViewSystem) then
550 call this.m_view.destroy()
551 endif
552 if (thistype.m_useFocusSystem) then
553 call this.m_focus.destroy()
554 endif
555 if (thistype.m_useMovementSystem) then
556 call this.m_movement.destroy()
557 endif
558 if (thistype.m_useFightSystem) then
559 call this.m_fight.destroy()
560 endif
561 if (thistype.m_useRevivalSystem) then
562 call this.m_revival.destroy()
563 endif
564 if (thistype.m_useInventorySystem) then
565 call this.m_inventory.destroy()
566 endif
567 if (thistype.m_useTalkLogSystem) then
568 call this.m_talkLog.destroy()
569 endif
570 endmethod
571
572 //Automatic destruction when player leaves
573 private method onDestroy takes nothing returns nothing
574 //start members
575 set this.m_user = null
576 //members
577 loop
578 exitwhen (this.m_spells.empty())
579 call ASpell(this.m_spells.back()).destroy()
580 endloop
581 call this.m_spells.destroy()
582
583 call this.removeUnit()
584 if (thistype.m_destroyOnPlayerLeaves or thistype.m_shareOnPlayerLeaves) then
585 call this.destroyLeaveTrigger()
586 endif
587 if (thistype.m_destroyOnDeath) then
588 call this.destroyDeathTrigger()
589 endif
590 call this.destroySystems()
591 endmethod
592
593 /**
594 * Call this method before you use this class!
595 * @param destroyOnPlayerLeaves If this value is true the character will be destroyed when his owner leaves game.
596 * @param shareOnPlayerLeaves If this value is true control over character will be shared with other character owners.
597 * @param destroyOnDeath If this value is false the character will be set unmovable when he dies otherwise he will be destroyed.
598 * @param useViewSystem Shows if the view system is used.
599 * @param useFocusSystem Shows if the focus system is used.
600 * @param useMovementSystem Shows if the movement system is used.
601 * @param useFightSystem Shows if the fight system is used.
602 * @param useRevivalSystem Shows if the revival system is used.
603 * @param useInventorySystem Shows if the inventory system is used.
604 * @param useTalkLogSystem Shows if the talk log system is used.
605 * @see AView
606 * @see AFocus
607 * @see AMovement
608 * @see AFight
609 * @see ARevival
610 * @see AInventory
611 * @see ATalkLog
612 */
613 public static method init takes boolean removeUnitOnDestruction, boolean destroyOnPlayerLeaves, boolean shareOnPlayerLeaves, boolean destroyOnDeath, boolean useViewSystem, boolean useFocusSystem, boolean useMovementSystem, boolean useFightSystem, boolean useRevivalSystem, boolean useInventorySystem, boolean useTalkLogSystem returns nothing
614 //static start members
615 set thistype.m_removeUnitOnDestruction = removeUnitOnDestruction
616 set thistype.m_destroyOnPlayerLeaves = destroyOnPlayerLeaves
617 set thistype.m_shareOnPlayerLeaves = shareOnPlayerLeaves
618 set thistype.m_destroyOnDeath = destroyOnDeath
619 set thistype.m_useViewSystem = useViewSystem
620 set thistype.m_useFocusSystem = useFocusSystem
621 set thistype.m_useMovementSystem = useMovementSystem
622 set thistype.m_useFightSystem = useFightSystem
623 set thistype.m_useRevivalSystem = useRevivalSystem
624 set thistype.m_useInventorySystem = useInventorySystem
625 set thistype.m_useTalkLogSystem = useTalkLogSystem
626
627 debug if (destroyOnPlayerLeaves and shareOnPlayerLeaves) then
628 debug call thistype.staticPrint("destroyOnPlayerLeaves and shareOnPlayerLeaves can not be set true at the same time.")
629 debug endif
630 debug if (destroyOnDeath and useRevivalSystem) then
631 debug call thistype.staticPrint("You're using destroy on death and use revival system options at the same time.")
632 debug endif
633 endmethod
634
635 public static method removeUnitOnDestruction takes nothing returns boolean
636 return thistype.m_removeUnitOnDestruction
637 endmethod
638
639 public static method destroyOnPlayerLeaves takes nothing returns boolean
640 return thistype.m_destroyOnPlayerLeaves
641 endmethod
642
643 public static method shareOnPlayerLeaves takes nothing returns boolean
644 return thistype.m_shareOnPlayerLeaves
645 endmethod
646
647 public static method destroyOnDeath takes nothing returns boolean
648 return thistype.m_destroyOnDeath
649 endmethod
650
651 public static method useViewSystem takes nothing returns boolean
652 return thistype.m_useViewSystem
653 endmethod
654
655 public static method useFocusSystem takes nothing returns boolean
656 return thistype.m_useFocusSystem
657 endmethod
658
659 public static method useMovementSystem takes nothing returns boolean
660 return thistype.m_useMovementSystem
661 endmethod
662
663 public static method useFightSystem takes nothing returns boolean
664 return thistype.m_useFightSystem
665 endmethod
666
667 public static method useRevivalSystem takes nothing returns boolean
668 return thistype.m_useRevivalSystem
669 endmethod
670
671 public static method useInventorySystem takes nothing returns boolean
672 return thistype.m_useInventorySystem
673 endmethod
674
675 public static method useTalkLogSystem takes nothing returns boolean
676 return thistype.m_useTalkLogSystem
677 endmethod
678
679 /**
680 * Each human playing player can own exact one character.
681 * Use this method to set the unit of a player character.
682 * @param user The owner of the character.
683 * @param usedUnit The unit of the character.
684 * @return Returns player character.
685 */
686 public static method setPlayerCharacter takes player user, unit usedUnit returns thistype
687 local thistype character = thistype.create(user, usedUnit)
688 set thistype.m_playerCharacter[GetPlayerId(user)] = character
689 return character
690 endmethod
691
692 /// @param user The owner of the character.
693 /// @return The character instance.
694 public static method playerCharacter takes player user returns thistype
695 return thistype.m_playerCharacter[GetPlayerId(user)]
696 endmethod
697
698 /// If character will be destroyed automaticly you don't have to call this method.
699 /// @param user The owner of the character.
700 public static method destroyPlayerCharacter takes player user returns nothing
701 call thistype.destroy(thistype.m_playerCharacter[GetPlayerId(user)])
702 endmethod
703
704 //static convenience methods
705
706 /// @todo You could also check it by only comparing with the units owner character unit.
707 public static method getCharacterByUnit takes unit usedUnit returns thistype
708 return AHashTable.global().handleInteger(usedUnit, "ACharacter")
709 endmethod
710
711 public static method isUnitCharacter takes unit usedUnit returns boolean
712 return thistype.getCharacterByUnit(usedUnit) != 0
713 endmethod
714
715 public static method getFirstCharacter takes nothing returns thistype
716 local integer i
717 local player user
718 set i = 0
719 loop
720 exitwhen (i == bj_MAX_PLAYERS)
721 set user = Player(i)
722 if (thistype.playerCharacter(user) != 0) then
723 set user = null
724 return thistype.playerCharacter(user)
725 endif
726 set user = null
727 set i = i + 1
728 endloop
729 return 0
730 endmethod
731
732 public static method displayMessageByUser takes player user, integer messageType, string message returns nothing
733 call thistype.playerCharacter(user).displayMessage(messageType, message)
734 endmethod
735
736 public static method setAllMovable takes boolean movable returns nothing
737 local integer i
738 local player user
739 set i = 0
740 loop
741 exitwhen (i == bj_MAX_PLAYERS)
742 set user = Player(i)
743 if (thistype.playerCharacter(user) != 0) then
744 call thistype.playerCharacter(user).setMovable(movable)
745 endif
746 set user = null
747 set i = i + 1
748 endloop
749 endmethod
750
751 /// Displays a message to each owner of every character.
752 public static method displayMessageToAll takes integer messageType, string message returns nothing
753 local integer i
754 local player user
755 set i = 0
756 loop
757 exitwhen (i == bj_MAX_PLAYERS)
758 set user = Player(i)
759 if (thistype.playerCharacter(user) != 0) then
760 call thistype.playerCharacter(user).displayMessage(messageType, message)
761 endif
762 set user = null
763 set i = i + 1
764 endloop
765 endmethod
766
767 public static method countAllPlaying takes nothing returns integer
768 local integer i
769 local player user
770 local integer result = 0
771 set i = 0
772 loop
773 exitwhen (i == bj_MAX_PLAYERS)
774 set user = Player(i)
775 if (IsPlayerPlayingUser(user) and thistype.playerCharacter(user) != 0) then
776 set result = result + 1
777 endif
778 set user = null
779 set i = i + 1
780 endloop
781 return result
782 endmethod
783
784 public static method addLevelsToAll takes integer levels, boolean showEffect returns nothing
785 local integer i
786 local player user
787 set i = 0
788 loop
789 exitwhen (i == bj_MAX_PLAYERS)
790 set user = Player(i)
791 if (thistype.playerCharacter(user) != 0) then
792 call thistype.playerCharacter(user).addLevels(levels, showEffect)
793 endif
794 set user = null
795 set i = i + 1
796 endloop
797 endmethod
798
799 public static method addSkillPointsToAll takes integer skillPoints returns nothing
800 local integer i
801 local player user
802 set i = 0
803 loop
804 exitwhen (i == bj_MAX_PLAYERS)
805 set user = Player(i)
806 if (thistype.playerCharacter(user) != 0) then
807 call thistype.playerCharacter(user).addSkillPoints(skillPoints)
808 endif
809 set user = null
810 set i = i + 1
811 endloop
812 endmethod
813
814 public static method addExperienceToAll takes integer experience, boolean showEffect returns nothing
815 local integer i
816 local player user
817 set i = 0
818 loop
819 exitwhen (i == bj_MAX_PLAYERS)
820 set user = Player(i)
821 if (thistype.playerCharacter(user) != 0) then
822 call thistype.playerCharacter(user).addExperience(experience, showEffect)
823 endif
824 set user = null
825 set i = i + 1
826 endloop
827 endmethod
828
829 public static method addStrengthToAll takes integer strength returns nothing
830 local integer i
831 local player user
832 set i = 0
833 loop
834 exitwhen (i == bj_MAX_PLAYERS)
835 set user = Player(i)
836 if (thistype.playerCharacter(user) != 0) then
837 call thistype.playerCharacter(user).addStrength(strength)
838 endif
839 set user = null
840 set i = i + 1
841 endloop
842 endmethod
843
844 public static method addAgilityToAll takes integer agility returns nothing
845 local integer i
846 local player user
847 set i = 0
848 loop
849 exitwhen (i == bj_MAX_PLAYERS)
850 set user = Player(i)
851 if (thistype.playerCharacter(user) != 0) then
852 call thistype.playerCharacter(user).addAgility(agility)
853 endif
854 set user = null
855 set i = i + 1
856 endloop
857 endmethod
858
859 public static method addIntelligenceToAll takes integer intelligence returns nothing
860 local integer i
861 local player user
862 set i = 0
863 loop
864 exitwhen (i == bj_MAX_PLAYERS)
865 set user = Player(i)
866 if (thistype.playerCharacter(user) != 0) then
867 call thistype.playerCharacter(user).addIntelligence(intelligence)
868 endif
869 set user = null
870 set i = i + 1
871 endloop
872 endmethod
873
874 public static method addGoldToAll takes integer gold returns nothing
875 local integer i
876 local player user
877 set i = 0
878 loop
879 exitwhen (i == bj_MAX_PLAYERS)
880 set user = Player(i)
881 if (thistype.playerCharacter(user) != 0) then
882 call thistype.playerCharacter(user).addGold(gold)
883 endif
884 set user = null
885 set i = i + 1
886 endloop
887 endmethod
888
889 public static method addLumberToAll takes integer lumber returns nothing
890 local integer i
891 local player user
892 set i = 0
893 loop
894 exitwhen (i == bj_MAX_PLAYERS)
895 set user = Player(i)
896 if (thistype.playerCharacter(user) != 0) then
897 call thistype.playerCharacter(user).addLumber(lumber)
898 endif
899 set user = null
900 set i = i + 1
901 endloop
902 endmethod
903
904 public static method allUnitsAreInRect takes rect usedRect returns boolean
905 local integer i
906 local player user
907 set i = 0
908 loop
909 exitwhen (i == bj_MAX_PLAYERS)
910 set user = Player(i)
911 if (thistype.playerCharacter(user) != 0) then
912 if ((thistype.playerCharacter(user).unit() == null) or (not RectContainsUnit(usedRect, thistype.playerCharacter(user).unit()))) then //RectContainsUnit shouldn't be that slow
913 return false
914 endif
915 endif
916 set user = null
917 set i = i + 1
918 endloop
919 return true
920 endmethod
921
922 public static method panCameraToAll takes nothing returns nothing
923 local integer i
924 local player user
925 set i = 0
926 loop
927 exitwhen (i == bj_MAX_PLAYERS)
928 set user = Player(i)
929 if (thistype.playerCharacter(user) != 0) then
930 call thistype.playerCharacter(user).panCamera()
931 endif
932 set user = null
933 set i = i + 1
934 endloop
935 endmethod
936
937 public static method panCameraSmartToAll takes nothing returns nothing
938 local integer i
939 local player user
940 set i = 0
941 loop
942 exitwhen (i == bj_MAX_PLAYERS)
943 set user = Player(i)
944 if (thistype.playerCharacter(user) != 0) then
945 call thistype.playerCharacter(user).panCameraSmart()
946 endif
947 set user = null
948 set i = i + 1
949 endloop
950 endmethod
951
952 public static method showAll takes boolean show returns nothing
953 local integer i
954 local player user
955 set i = 0
956 loop
957 exitwhen (i == bj_MAX_PLAYERS)
958 set user = Player(i)
959 if (thistype.playerCharacter(user) != 0) then
960 call thistype.playerCharacter(user).show(show)
961 endif
962 set user = null
963 set i = i + 1
964 endloop
965 endmethod
966
967 public static method enableShrineForAll takes AShrine shrine, boolean showMessage returns nothing
968 local integer i
969 local player user
970 debug if (not thistype.m_useRevivalSystem) then
971 debug call thistype.staticPrint("Revival system is not enabled.")
972 debug return
973 debug endif
974 set i = 0
975 loop
976 exitwhen (i == bj_MAX_PLAYERS)
977 set user = Player(i)
978 if (thistype.playerCharacter(user) != 0) then
979 call shrine.enableForCharacter(thistype.playerCharacter(user), showMessage)
980 endif
981 set user = null
982 set i = i + 1
983 endloop
984 endmethod
985
986 public static method setToRandomPointOnRectForAll takes rect whichRect returns nothing
987 local integer i
988 local player user
989 set i = 0
990 loop
991 exitwhen (i == bj_MAX_PLAYERS)
992 set user = Player(i)
993 if (thistype.playerCharacter(user) != 0) then
994 call SetUnitToRandomPointOnRect(thistype.playerCharacter(user).unit(), whichRect)
995 endif
996 set user = null
997 set i = i + 1
998 endloop
999 endmethod
1000 endstruct
1001
1002 endlibrary